class Login {
  constructor () {
    this.bindEvent()
  }

  bindEvent () {
    $('.register-btn span').on('click', ()=>{
      this.validUser()
    })
  }

  validUser() {
    let username = $('#username').val()
    let password = $('#password').val()

    let userInfo = localStorage.getItem('userInfo')

    if (userInfo) {
      userInfo = JSON.parse(userInfo)

      let isPass = userInfo.some(item => {
        return item.username === username && item.password===password
      })

      if (isPass) {

        localStorage.setItem('login',username)

        $('.success').show()
        setTimeout(()=>{
          location.href = '/'
        },1500)
      } else {
        alert('用户名或密码错误')
      }
    } else {
      alert('用户名或密码错误')
    }
  }
}

new Login()
